package ttsdemo;


import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;


public class TTSDemo {


    private String voice_name;
    private String text;
    
    private TTSDemo(){
        this.voice_name = "kevin";
    }


    public void setText(String text) {
        this.text = text;
    }


    //name = kevin||kevin16||alan
    public void setVoice(String name) {
        this.voice_name = name;
    }


    public void speak() {
        Voice voice;
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice(voice_name);
        voice.allocate();
        voice.speak(text);
        voice.deallocate();
    }


    public void createAudioFile(String path) {
        Voice voice;
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice(voice_name);
        FreeTTS freeTTS = new FreeTTS(voice);
        freeTTS.setAudioFile(path);
        freeTTS.startup();
        voice.allocate();
        voice.speak(text);
        voice.deallocate();
        freeTTS.shutdown();
    }


    public static void main(String[] args) {
        String text = "Hello, World";
        TTSDemo demo = new TTSDemo();
        demo.setText(text);
        demo.speak();
        demo.createAudioFile("freeTTS_demo.wav");
    }
}
